package com.mall.server.controller.pms;


import com.mall.model.domain.PmsSkuStock;
import com.mall.model.vo.CommonResult;
import com.mall.server.service.pms.PmsSkuStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/sku")
public class PmsSkuStockController {


    @Autowired
    private PmsSkuStockService skuStockService;

    @PostMapping("/update/{pid}")
    public CommonResult updateSkuStock(@PathVariable("pid") Integer pid, @RequestBody List<PmsSkuStock> skuStockList) {

        skuStockService.updateSkuStock(pid, skuStockList);
        return CommonResult.success(null);
    }

    @GetMapping("/{pid}")
    public CommonResult findByPidAndCode(@PathVariable("pid") Integer pid, String keyword) {

        List<PmsSkuStock> skuStockList = skuStockService.findByPidAndCode(pid, keyword);
        return CommonResult.success(skuStockList);
    }

}
